<?php
namespace app\api\controller;
use support\think\Cache;
use support\Request;
use think\facade\Db;
class UpdateFileController extends Base
{
    public function getObsKey(Request $request)
    {
        $path=$request->input('path','');
        $type=$request->input('type','');
        if($type=='local'){
            $key='ObsKey:'.uniqid();
            $arr=[
                'key'=>$key,
                'url'=>'api/updateFile/updateImg',
                'path'=>$path,
            ];
            Cache::set($key, $arr,600);
            s($arr);
        }

        s();
    }
    public function updateImg(Request $request)
    {
        $key=$request->post('key');
        $path=$request->post('path','');
        $all=Cache::get($key);
        if($all){
            $file = $request->file('file');
            if ($file && $file->isValid()) {
                if($file->getSize() > 10*1024*1024){e('附件大小不能超过10M');}
                $path = '/local'.$path;
                $file->move(public_path().$path);
//                dump(public_path().$path);
                s($path);
            }
        }
        e();
    }
}
